package thread;

public class SyncDemo5 {
    public static void main(String[] args) {
        Coo coo = new Coo();
        Thread thread = new Thread(coo::methodA);
        Thread thread1 = new Thread(coo::methodB);

        thread.start();
        thread1.start();
    }
}


class Coo{
    public synchronized void methodA(){
        try {
            Thread t=Thread.currentThread();
            System.out.println(t.getName());
            Thread.sleep(3000);
            System.out.println(t.getName());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    public synchronized void methodB(){
        try {
            Thread t=Thread.currentThread();
            System.out.println(t.getName());
            Thread.sleep(3000);
            System.out.println(t.getName());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}